﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;

namespace ArunimaErp.WebForm
{
    public partial class TotalDprForm : System.Web.UI.Page
    {
        private ReportDocument TotalDprRptDoc = new ReportDocument();

        private rerpDataSet totalDprDs = new rerpDataSet(); // .xsd file name
        private DataTable totalDprDt = new DataTable();
        private string _query = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            // Just set the name of data table
            totalDprDt.TableName = "production_daily_report";

            if (dateTimePicker1.Text == "" || dateTimePicker2.Text == "")
            {
                _query = "select "
                            + "BuyerName, PoNo, StyleNo, "
                            + "ProductionDailyReportId, "
                            + " dp.Date, Floor, Line, Cutting, "
                            + " SentPrintEmb, ReceivedPrintEmb, "
                            + " SewingInput, TodaySewing, SentWash, "
                            + " ReceivedWash, TodayFinish, OrderQuantity "
                            + " from "
                            + " ProductionDailyReport dp, PoStyle ps, StyleInfo s, BuyerInfo b "
                            + " where "
                            + " dp.PoStyleId = ps.PoStyleId and "
                            + " ps.StyleId = s.StyleId and "
                            + " s.BuyerId = b.BuyerId and "
                            + " dp.Date = '" + DateTime.Now.ToString(("yyy-MM-dd")) + "' ";
            }
            else
            {
                _query = "select "
                            + "BuyerName, PoNo, StyleNo, "
                            + "ProductionDailyReportId, "
                            + " dp.Date, Floor, Line, Cutting, "
                            + " SentPrintEmb, ReceivedPrintEmb, "
                            + " SewingInput, TodaySewing, SentWash, "
                            + " ReceivedWash, TodayFinish, OrderQuantity "
                            + " from "
                            + " ProductionDailyReport dp, PoStyle ps, StyleInfo s, BuyerInfo b "
                            + " where "
                            + " dp.PoStyleId = ps.PoStyleId and "
                            + " ps.StyleId = s.StyleId and "
                            + " s.BuyerId = b.BuyerId and "
                            + " dp.Date between '" + dateTimePicker1.Text + "' and '" + dateTimePicker2.Text + "' ";
            }

            totalDprDt = DatabaseHelper.select(_query); //This function is located below this function
            
            totalDprDs.Tables["production_daily_report"].Clear();
            totalDprDs.Tables["production_daily_report"].Merge(totalDprDt);
            // Your .rpt file path will be below
            TotalDprRptDoc.Load(Server.MapPath("../WebForm/TotalDprReport.rpt"));

            //set dataset to the report viewer.
            TotalDprRptDoc.SetDataSource(totalDprDs);
            CrystalReportViewer1.ReportSource = TotalDprRptDoc;
        }
       

        protected void Button1_Click(object sender, EventArgs e)
        {
            // Just set the name of data table
            totalDprDt.TableName = "production_daily_report";

            if (dateTimePicker1.Text == "" || dateTimePicker2.Text == "")
            {
                _query = "select "
                            + "BuyerName, PoNo, StyleNo, "
                            + "ProductionDailyReportId, "
                            + " dp.Date, Floor, Line, Cutting, "
                            + " SentPrintEmb, ReceivedPrintEmb, "
                            + " SewingInput, TodaySewing, SentWash, "
                            + " ReceivedWash, TodayFinish, OrderQuantity "
                            + " from "
                            + " ProductionDailyReport dp, PoStyle ps, StyleInfo s, BuyerInfo b "
                            + " where "
                            + " dp.PoStyleId = ps.PoStyleId and "
                            + " ps.StyleId = s.StyleId and "
                            + " s.BuyerId = b.BuyerId and "
                            + " dp.Date = '" + DateTime.Now.ToString(("yyy-MM-dd")) + "' ";
            }
            else
            {
                _query = "select "
                            + "BuyerName, PoNo, StyleNo, "
                            + "ProductionDailyReportId, "
                            + " dp.Date, Floor, Line, Cutting, "
                            + " SentPrintEmb, ReceivedPrintEmb, "
                            + " SewingInput, TodaySewing, SentWash, "
                            + " ReceivedWash, TodayFinish, OrderQuantity "
                            + " from "
                            + " ProductionDailyReport dp, PoStyle ps, StyleInfo s, BuyerInfo b "
                            + " where "
                            + " dp.PoStyleId = ps.PoStyleId and "
                            + " ps.StyleId = s.StyleId and "
                            + " s.BuyerId = b.BuyerId and "
                            + " dp.Date between '" + dateTimePicker1.Text + "' and '" + dateTimePicker2.Text + "' ";
            }

            totalDprDt = DatabaseHelper.select(_query); //This function is located below this function
            
            totalDprDs.Tables["production_daily_report"].Clear();
            totalDprDs.Tables["production_daily_report"].Merge(totalDprDt);
            // Your .rpt file path will be below
            TotalDprRptDoc.Load(Server.MapPath("../WebForm/TotalDprReport.rpt"));

            //set dataset to the report viewer.
            TotalDprRptDoc.SetDataSource(totalDprDs);
            CrystalReportViewer1.ReportSource = TotalDprRptDoc;
        }
    }
}